import datetime
import sched, time
import threading

from daily_check import checkUpdate
from detail import run_detail_spider
from listSpider import run_list_spider

scheduler = sched.scheduler(time.time, time.sleep)
DELAY = 3600

def crawl_detail():
    time.sleep(60)
    run_detail_spider()

def do(delay):
    hour = datetime.datetime.now().hour
    if hour % 2 == 0:
        t1 = threading.Thread(target=checkUpdate)
        t1.start()
    scheduler.enter(delay, 0, do, (delay,))


if __name__ == '__main__':
    threading.Thread(target=crawl_detail).start()
    scheduler.enter(0, 0, do, (3600,))
    scheduler.run()
